package com.guoxin.concurrentprogramming.chapter2;

import java.util.concurrent.TimeUnit;

/**
 * @author guoxin
 * @date 2019/7/15
 */
public class InterruptThread {

    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(() -> {
            System.out.println("子线程启动");
            while (true) {
                if (Thread.interrupted()) {
                    break;
                }
            }
            System.out.println("子线程停止");
        });

        TimeUnit.SECONDS.sleep(1);
        t.start();
        t.interrupt();
    }
}
